import React, { useState, useEffect } from 'react';
import { useRequest } from 'ahooks';

export default function (props) {
  const [state, setState] = useState();

  async function getEmail(search) {
    console.log('debounce getEmail 防抖的实现', search);
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve('000000');
      }, 300);
    });
  }

  const { data, loading, run } = useRequest(getEmail, {
    debounceWait: 2000,
    manual: true,
  });

  const inputFn = (e) => {
    console.log(e.target.value);
  };

  return (
    <div>
      input 防抖 的使用:
      <input onChange={(e) => run(e.target.value)} />
      {loading ? <h1>loading</h1> : data}
    </div>
  );
}
